package com.elai.operate.controller;

import java.util.List;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.operate.domain.OperateEquityDO;
import com.elai.operate.service.OperateEquityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 权益绑定Controller
 *
 * @author elai
 * @date 2021-04-04
 */
@RestController
@RequestMapping("/operate/equity")
public class OperateEquityController extends BaseController
{
    @Autowired
    private OperateEquityService operateEquityService;

    /**
     * 查询权益绑定列表
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperateEquityDO operateEquity)
    {
        startPage();
        List<OperateEquityDO> list = operateEquityService.selectOperateEquityList(operateEquity);
        return getDataTable(list);
    }

    /**
     * 导出权益绑定列表
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:export')")
    @Log(title = "权益绑定", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperateEquityDO operateEquity)
    {
        List<OperateEquityDO> list = operateEquityService.selectOperateEquityList(operateEquity);
        ExcelUtil<OperateEquityDO> util = new ExcelUtil<OperateEquityDO>(OperateEquityDO.class);
        return util.exportExcel(list, "equity");
    }

    /**
     * 获取权益绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(operateEquityService.selectOperateEquityById(id));
    }

    /**
     * 新增权益绑定
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:add')")
    @Log(title = "权益绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperateEquityDO operateEquity)
    {
        return toAjax(operateEquityService.insertOperateEquity(operateEquity));
    }

    /**
     * 修改权益绑定
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:edit')")
    @Log(title = "权益绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperateEquityDO operateEquity)
    {
        return toAjax(operateEquityService.updateOperateEquity(operateEquity));
    }

    /**
     * 删除权益绑定
     */
    @PreAuthorize("@ss.hasPermi('operate:equity:remove')")
    @Log(title = "权益绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operateEquityService.deleteOperateEquityByIds(ids));
    }
}
